/**
 * 菜单详情对话框
 */
var ShopApplyDlg = {
    ShopApplyDlgData: {},
    ztreeInstance: null,
    validateFields: {
    	user_name: {
            validators: {
                notEmpty: {
                    message: '姓名不能为空'
                }
            }
        },
        binding_phone: {
            validators: {
                notEmpty: {
                    message: '绑定手机不能为空'
                }
            }
        },
        isUp: {
            validators: {
                notEmpty: {
                    message: '请选择是否矿机主升级到店铺'
                }
            }
        }
    }
};

/**
 * 清除数据
 */
ShopApplyDlg.clearData = function () {
    this.ShopApplyDlgData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
ShopApplyDlg.set = function (key, val) {
        this.ShopApplyDlgData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
        return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
ShopApplyDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
ShopApplyDlg.close = function () {
    parent.layer.close(window.parent.ShopApply.layerIndex);
}

/**
 * 收集数据
 */
ShopApplyDlg.collectData = function () {
    this.set('user_name').set('binding_phone').set('recommendation_no').set('flow_no').set('pay_type').set('pay_channel').set('pay_money').set('isUp')
    if($("#pay_time").val()!="")
    {
    	
    	this.set('pay_time');
    }
   
}

/**
 * 验证数据是否为空
 */
ShopApplyDlg.validate = function () {
    $('#shopApplyInfoForm').data("bootstrapValidator").resetForm();
    $('#shopApplyInfoForm').bootstrapValidator('validate');
    return $("#shopApplyInfoForm").data('bootstrapValidator').isValid();
}
/**
 * 提交添加用户
 */
ShopApplyDlg.addSubmit = function () {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/partnerApply/addShop", function (data) {
        if(data.code == 200) {
            Feng.success("添加成功!");
            window.parent.ShopApply.table.refresh();
            ShopApplyDlg.close();
        }else{
            Feng.error(data.message);
        }
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.ShopApplyDlgData);
    ajax.start();
    
    
}
$(function()
{
	Feng.initValidator("shopApplyInfoForm", ShopApplyDlg.validateFields);
	$("#isUp").change(function()
    {
		if($(this).val()=="0")
		{
			  $("#shopApplyInfoForm").data('bootstrapValidator').addField('flow_no', {
				   
					validators: {
						notEmpty: {
							message: '缴费回执号不能为空'
						}
					}
				});
			  $("#shopApplyInfoForm").data('bootstrapValidator').addField('pay_money', {
				   
					validators: {
						notEmpty: {
							message: '实付金额不能为空'
						},
		                greaterThan: {
		                    value: 1
		                },
		                lessThan: {
		                    value: 1000000
		                }
					}
				});
			  $("#shopApplyInfoForm").data('bootstrapValidator').addField('pay_type', {
				   
					validators: {
						notEmpty: {
							message: '支付方式不能为空'
						},
		                greaterThan: {
		                    value: 1
		                },
		                lessThan: {
		                    value: 1000000
		                }
					}
				});
			  $("#shopApplyInfoForm").data('bootstrapValidator').addField('pay_channel', {
				   
					validators: {
						notEmpty: {
							message: '支付渠道不能为空'
						}
					}
				});
			  $("#shopApplyInfoForm").data('bootstrapValidator').addField('pay_time', {
				   
					validators: {
						notEmpty: {
							message: '支付时间不能为空'
						}
					}
				});
			  
			  $('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('flow_no', true);
			  $('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('pay_money', true);
			  $('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('pay_type', true);
			  $('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('pay_channel', true);
			  $('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('pay_time', true);
			  
				$('#flow_no').removeAttr("disabled");
				$('#pay_money').removeAttr("disabled");
				$('#pay_type').removeAttr("disabled");
				$('#pay_channel').removeAttr("disabled");
				$('#pay_time').removeAttr("disabled");
			  
		}else
		{
			if(typeof($('#shopApplyInfoForm').data('bootstrapValidator').options.fields["flow_no"])!="undefined")
			{
				$('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('flow_no', false);
				$('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('pay_money', false);
				$('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('pay_type', false);
				$('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('pay_channel', false);
				$('#shopApplyInfoForm').data('bootstrapValidator').enableFieldValidators('pay_time', false);
			}
			
			$('#flow_no').val("");
			$('#pay_money').val("");
			$('#pay_type').val("");
			$('#pay_channel').val("");
			$('#pay_time').val("");
			
			
			$('#flow_no').attr("disabled",true);
			$('#pay_money').attr("disabled",true);
			$('#pay_type').attr("disabled",true);
			$('#pay_channel').attr("disabled",true);
			$('#pay_time').attr("disabled",true);
		}
	});
});